from eventServer import eventServer
from collectCube import CollectCube
from soundServer import sound

class SpikeHat(CollectCube):
    
    def __init__(self):
        CollectCube.__init__(self)
        
        self.setVar("texture", "spikeHat")
        
        self.setVar("timedItem", True)
        self.setVar("lifeSpan", 10)
        self.setVar("lifeBlinkTime", 2)
                                
    def onCollision(self, dist, vec, side, sideType, above, toward, ignoreSurface, object):
        CollectCube.onCollision(self, dist, vec, side, sideType, above, toward, ignoreSurface, object)

        p = self.getVar("itemPlayer")
        if(not(p == None)):
            if(not(p == object)):
                if(object.hasVar("base")):
                    b = object.getVar("base")
                    if(b == 'player'):
                        fromPlayer = p.getVar("player")
                        toPlayer = object.getVar("player")
                        eventServer.pull('playerStomp',{'fromPlayer':fromPlayer,'toPlayer':toPlayer})
                        eventServer.pull("itemCollected", {"player":fromPlayer, "collected":None})
                        sound.play("spikeHat_kill")